const app = getApp()
Page({

  data: {
    scrollHeight: 0,
    faultList: [
      {
        id: 0,
        probability: 90,
        describe: "摄像头频繁自启动，可能是电源适配器或线缆接触不良导致。",
        suggest: ["检查电源适配器是否松动", "确认线缆链接是否牢固", "测量输出电压是否正常"],
        image: app.getImgUrl('solution.png'),
        expand: false,
      },
      {
        id: 1,
        probability: 80,
        describe: "监控画面丢失，可能是硬盘录像机(DVR/NVR)存储故障或硬盘损坏。",
        suggest: ["检查硬盘指示灯是否正常", "尝试格式化硬盘并重建分区", "更换备用硬盘测试"],
        image: app.getImgUrl('solution.png'),
        expand: false,
      },
      {
        id: 2,
        probability: 70,
        describe: "多画面卡顿，可能是网络交换机带宽不足或网线传输性能下降。",
        suggest: ["用测线仪检测网线速率", "升级千兆交换机", "检查水晶头氧化情况"],
        image: app.getImgUrl('solution.png'),
        expand: false,
      },
      {
        id: 3,
        probability: 60,
        describe: "远程无法查看，可能是路由器端口映射错误或防火墙策略拦截。",
        suggest: ["验证DDNS配置状态", "检查554/8000端口开放情况", "关闭防火墙测试连通性"],
        image: app.getImgUrl('solution.png'),
        expand: false,
      }
    ],
    faultChannalList: [
      {
        id: 0,
        type: 'video',
        name: '通道1-MIPC3312(P)-X V4.0',
        time: '2025-03-23 14:30:25',
        total: '28天15小时23分',
        period: '2025-03-01 至 2025-03-31',
        count: '30个',
        faultLength: '8小时36分',
        ratio: '1',
        past7dRatio: '1',
      },
      {
        id: 1,
        type: 'image',
        name: '通道2-MIPC3315(P)-X V4.2',
        time: '2025-03-24 09:45:30',
        total: '29天2小时10分',
        period: '2025-03-01 至 2025-03-31',
        count: '28个',
        faultLength: '5小时20分',
        ratio: '0.98',
        past7dRatio: '0.97',
      },
      {
        id: 2,
        type: 'video',
        name: '通道3-MIPC3318(P)-X V5.0',
        time: '2025-03-25 16:20:15',
        total: '30天0小时0分',
        period: '2025-03-01 至 2025-03-31',
        count: '32个',
        faultLength: '12小时10分',
        ratio: '0.96',
        past7dRatio: '0.95',
      },
      {
        id: 3,
        type: 'image',
        name: '通道4-MIPC3320(P)-X V4.5',
        time: '2025-03-26 08:10:05',
        total: '27天8小时0分',
        period: '2025-03-01 至 2025-03-31',
        count: '25个',
        faultLength: '3小时50分',
        ratio: '0.99',
        past7dRatio: '0.98',
      }
    ],
    scaleSVG: app.getImgUrl('timeLine.svg'),
    barPNG: app.getImgUrl('timeLineBar.png'),
    bar1PNG: app.getImgUrl('timeLineBar1.png'),
    bar2PNG: app.getImgUrl('timeLineBar2.png')
  },

  onLoad() {
    this.calcScrollHeight()
  },

  calcScrollHeight() {
    const query = wx.createSelectorQuery();
    // 选择导航栏和筛选框元素
    query.select('.nav').boundingClientRect();
    query.select('.pageHeader').boundingClientRect();

    query.exec((res) => {
      if (res && res[0] && res[1]) {
        const navHeight = res[0].height;    // 导航栏高度
        const filterHeight = res[1].height; // 筛选框高度
        const windowHeight = wx.getWindowInfo().windowHeight; // 屏幕高度

        // 计算剩余高度，确保非负数
        const scrollHeight = Math.max(0, windowHeight - navHeight - filterHeight);

        this.setData({ scrollHeight });
      }
    });
  },
  changeExpand: function (e) {
    const index = e.currentTarget.dataset.index; // 获取点击项索引
    const path = `faultList[${index}].expand`; // 构造数据路径
    this.setData({
      [path]: !this.data.faultList[index].expand // 取反展开状态
    });
  },
  navigateTo(e) {
    const url = e.currentTarget.dataset
    app.navigateTo({
      url: url,
    })
  }
})